package com.fys.user.utils;

import com.fys.user.enums.ResultEnum;
import com.fys.user.vo.ResultVO;

/**
 * @author: fys
 * @description:
 * @create: 2020-07-23 16:39
 **/
public class ResultVOUtil {
    private final static Integer SUCCESS_CODE = 0;
    private final static Integer ERROR_CODE = -1;

    public static <T> ResultVO<T> success(T t){
        ResultVO<T> resultVO = new ResultVO<>();
        resultVO.setCode(SUCCESS_CODE);
        resultVO.setMsg("成功");
        resultVO.setData(t);
        return resultVO;
    }

    public static <T> ResultVO<T> success(){
        ResultVO<T> resultVO = new ResultVO<>();
        resultVO.setCode(SUCCESS_CODE);
        resultVO.setMsg("成功");
        return resultVO;
    }

    public static <T> ResultVO<T> error(T t){
        ResultVO<T> resultVO = new ResultVO<>();
        resultVO.setCode(ERROR_CODE);
        resultVO.setMsg("失败");
        resultVO.setData(t);
        return resultVO;
    }

    public static ResultVO error(ResultEnum resultEnum) {
        ResultVO resultVO = new ResultVO();
        resultVO.setCode(resultEnum.getCode());
        resultVO.setMsg(resultEnum.getMessage());
        return resultVO;
    }

}
